<?php

class AudioVideoTemplate extends DefaultTemplate {

	private array $entry;

	private array $lengthToMin = [
		"long"    => "> 45min",
		"medium"  => "10-45min",
		"short"   => "< 10min",
		"unknown" => "Unknown Length"
	];


	private function getMetadata($entry, ...$fields): string {
		$metadata = "";
		foreach ($fields as $field) if (isset($entry[$field]))
			$metadata .= "<i>$field:</i>&nbsp; $entry[$field]<br />";
		return $metadata;
	}

	private function getEntry($key): string {
		return $this->entry[$key] ?? "";
	}

	protected function generateEntry(array $entry): string {
		$year = date("Y", strtotime($entry["Date"]));
		$metadata = $this->getMetadata($entry, "By", "Type", "Date", "Event",
			"Organizer", "Hosts", "RecordedBy", "ThanksTo", "Location", "Note",
			"Language", "Duration");
		$licensing = $this->getMetadata($entry, "Copyright", "License");
		$media = explode(" ", $entry["Media"]);
		$lang = $entry["Lang"];
		$length = $entry["Length"];
		$this->entry = $entry;
		ob_start();
		include "audio_video_template.php";
		return ob_get_clean();
	}

}
